package Servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import jdbc_demo.my;

@WebServlet(name = "MyServlet")
public class MyServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //设置响应编码格式
        resp.setContentType("text/html;charset=utf-8");
        //
        String name = req.getParameter("name");
        String password = req.getParameter("password");
        System.out.println("当前输入为" + name+":"+password);
        if(my.compare(name,password)==1) {  //调用对象my.java , 为1时可执行
            System.out.println("info:Success!");
            resp.getWriter().write("<script>alert('登录成功！');window.location='http://localhost:8080/HelloWorld.html';</script>");
        } else {
            System.out.println("info:Failed!");
            resp.getWriter().write("<script>alert('登录失败！');window.location='http://localhost:8080/Main.html';</script>");
        }

    }
}
